package com.meila.cms.controller;


import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.meila.cms.auth.AuthClass;
import com.meila.cms.entity.AjaxObj;
import com.meila.cms.model.UserModel;
import com.meila.cms.services.IRoleService;
import com.meila.cms.services.IUserService;
import com.meila.cms.util.json.JsonUtil2;
import com.meila.cms.util.page.Pager;

@Controller
@RequestMapping("/after/user")
@AuthClass("login")
public class UserController {
	
	private IUserService userService;
 
	private IRoleService roleService;
 

	public IRoleService getRoleService() {
		return roleService;
	}

	@Inject
	public void setRoleService(IRoleService roleService) {
		this.roleService = roleService;
	}

	public IUserService getUserService() {
		return userService;
	}

	@Inject
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	/**
	 * 获取用户分页列表集合信息
	 * 
	 * @param model
	 * @return 获取用户分页列表集合信息
	 */
	@RequestMapping(value="/user_list",method = RequestMethod.GET)
	public String listUser(UserModel userModel,Model model) {
		 
		// 获取用户分页列表集合信息
		Pager<UserModel> listUser = userService.findUser(userModel);
		// 保存用户分页列表集合信息
		model.addAttribute("datas", listUser);
		
		model.addAttribute("jsondatas",JsonUtil2.toJSONList(listUser.getDatas()));
		
		return "user/user_list";
	}
	
	
	@RequestMapping(value="/user_list",method = RequestMethod.POST)
	@ResponseBody
	public List  listUser(UserModel userModel) {
		 
		// 获取用户分页列表集合信息
		Pager<UserModel> listUser = userService.findUser(userModel);
	 
		return listUser.getDatas();
	}
	/**
	 * 待认证用户列表
	 * @param userModel
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/approve_user_list",method = RequestMethod.GET)
	public String approve_user_list(UserModel userModel,Model model) {
		 
		// 获取用户分页列表集合信息
		userModel.setAuthentication(0);
		Pager<UserModel> listUser = userService.findUser(userModel);
		// 保存用户分页列表集合信息
		model.addAttribute("datas", listUser);
		
		model.addAttribute("jsondatas",JsonUtil2.toJSONList(listUser.getDatas()));
		
		return "user/approve_user_list";
	}
 
	
	@RequestMapping("/updateStatus")
	@ResponseBody
	public AjaxObj updateStatus(UserModel userModel) {
 
		AjaxObj  ajaxObj=userService.update(userModel);
		
		return ajaxObj;
	}
 
	
	@RequestMapping("/updateAuthentication")
	@ResponseBody
	public AjaxObj updateAuthentication(UserModel userModel) {
 
		AjaxObj  ajaxObj=userService.update(userModel);
		
		return ajaxObj;
	}
	
	@RequestMapping("/approvePerson")
	public String approvePerson(UserModel userModel,Model model) {
		
	    userModel=userService.load(userModel.getId());
		model.addAttribute("userModel", userModel);
	   
		return "user/approvePerson";
	}
	
	@RequestMapping("/approveFirm")
	public String approveFirm(UserModel userModel,Model model) {
		
	    userModel=userService.load(userModel.getId());
		model.addAttribute("userModel", userModel);
		
		return "user/approveFirm";
	}
 
	

}
